/*
*	javascript for mserver
*
**/
//(function (){
	if(typeof String.prototype.trim !== 'function') {
	  String.prototype.trim = function() {
	    return this.replace(/^\s+|\s+$/g, ''); 
	  }
	}
	function newDate(dateStr){
		//var dateStr="2011-08-03 09:15:11"; 
		var a=dateStr.split(" ");
		var d=a[0].split("-");
		if (d.length != 3 || !d[0] || !d[1] || !d[2])
			return null;
		var t=a[1].split(":");
		if (t.length != 3 || !t[0] || !t[1] || !t[2])
			return null ;
		var date = new Date(d[0],(d[1]-1),d[2],t[0],t[1],t[2]);
		return date ;
	}
	function onContact(ele){
		// update main navigater
		$('a[name="mainNavBar"]').each(function(i,ele){jQuery.attr(ele,'class','');});					
		jQuery.attr(ele,'class','active');
		
		onClickSideBar(ele);
	}
	function updateUser(){
		
 		try{
	 		var userName = $("input#userName").val().trim() ;
	 		var password = $("input#password").val().trim();
	 		var newPassword = $("input#newPassword").val().trim();
	 		var newPasswordConfirm = $("input#newPasswordConfirm").val().trim();
	 		var qq = $("input#qq").val().trim() ;
	 		var email = $("input#email").val().trim() ;
	 		var zhifubao = $("input#zhifubao").val().trim() ;
	 		var phone = $("input#phone").val().trim() ;
	 		if (userName == '' || password =='' || 
	 			newPassword == '' || newPasswordConfirm == '' ||
	 			 qq == '' || email == '' || zhifubao == '' || phone == '')
	 		{
	 			alert('所有输入项不能为空');
	 			return false;
	 		}
	 		if (newPassword != newPasswordConfirm)
	 		{
	 			alert('二次输入的密码不匹配');
	 			return false;
	 		}
			$.ajax({
				url: 'user',
				type: "get",
				async:false,
				dataType:"text",
				data: {
			        'actionType' : 'updateUser',
			        'userName' : userName,
			        'password': password,
			        'newPassword': newPassword,
			        'qq':qq,
			        'email':email,
			        'zhifubao':zhifubao,
			        'phone':phone
			    },
				success: function(data,textStatus) {
					if (data == '0')
					{
						alert('更新成功');
					}
					else
					{
						alert('更新失败:'+getErrMsg(data));
					}
		  		}
			});
		}catch(e){
			alert(e);
		}
		return false ;
	}
	function onUpdateUser(event){
		$('p#pOldPwd').show();
		$('p#pNewPwd').show();
		$('p#pNewPwdCfm').show();
		$('p#pPoint').hide();
		$('p#pUsedPoint').hide();
		$('p#pLeftPoint').hide();
		$('p#pReturnPoint').hide();
		$('p#pReturnRatio').hide();
		$('input#btnUpdateUser').hide();
		$('input#btnUpdateUser1').show();
	}
	function onQueryReturnRecord(){
		var pageNo = '1';
		var account = $('input#account').val();
		var msgId = $('input#msgId').val().trim();
		var gameType = $('input#gameType').val().trim();
		var status = $('select#status').val();
		var minSendTime = 0 ;
		var maxSendTime = 0 ;
		var ip = $('input#ip').val().trim();
		if($("select#pageNo").length ==1 )
			pageNo=$("select#pageNo").val();

		var pSendDate = $('input#sendDate').val().trim();
		var pMinSendTime = $('input#minSendTime').val().trim() ;
		var pMaxSendTime = $('input#maxSendTime').val().trim() ;
		var minSendTime = 0 ;
		var maxSendTime = 0 ;

		if(pSendDate != '' && pMinSendTime != '')
		{
			//minSendTime = Date.parse(pSendDate + 'T' + pMinSendTime);
			var date = newDate(pSendDate + ' ' + pMinSendTime);
			if (date)
				minSendTime = Date.parse(date);
			else
			{
				alert('请输入正确日期');
				return false;
			}
		}
		if(pSendDate != '' && pMaxSendTime != '')
		{
			//maxSendTime = Date.parse(pSendDate + 'T' + pMaxSendTime);
			var date = newDate(pSendDate + ' ' + pMaxSendTime);
			if (date)
				maxSendTime = Date.parse(date);
			else
			{
				alert('请输入正确日期');
				return false;
			}
		}
					
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'queryReturnRecord',
					//'filterRight':filterRight,
					'status':status,
					'account':account,
					'pageNo':pageNo,
					'msgId':msgId,
					'gameType':gameType,
					'minSendTime':minSendTime,
					'maxSendTime':maxSendTime,
					'ip':ip
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					// clear previous mainDiv
					var preDlg = $("div#main>form"); 
					//preDlg.hide();
					$("div#main").empty();
					$("div#main").append(preDlg);
					$("div#main").append(data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}
	function onUserQueryAnswerRecord(){
		var pageNo = '1';
		var account = $('input#account').val();
		var msgId = $('input#msgId').val().trim();
		var gameType = $('input#gameType').val().trim();
		var status = $('select#status').val();
		var minSendTime = 0 ;
		var maxSendTime = 0 ;
		var ip = $('input#ip').val().trim();
		if($("select#pageNo").length ==1 )
			pageNo=$("select#pageNo").val();

		var pSendDate = $('input#sendDate').val().trim();
		var pMinSendTime = $('input#minSendTime').val().trim() ;
		var pMaxSendTime = $('input#maxSendTime').val().trim() ;
		var minSendTime = 0 ;
		var maxSendTime = 0 ;

		if(pSendDate != '' && pMinSendTime != '')
		{
			//minSendTime = Date.parse(pSendDate + 'T' + pMinSendTime);
			var date = newDate(pSendDate + ' ' + pMinSendTime);
			if (date)
				minSendTime = Date.parse(date);
			else
			{
				alert('请输入正确日期');
				return false;
			}
		}
		if(pSendDate != '' && pMaxSendTime != '')
		{
			//maxSendTime = Date.parse(pSendDate + 'T' + pMaxSendTime);
			var date = newDate(pSendDate + ' ' + pMaxSendTime);
			if (date)
				maxSendTime = Date.parse(date);
			else
			{
				alert('请输入正确日期');
				return false;
			}
		}
					
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'queryAnswerRecord',
					//'filterRight':filterRight,
					'status':status,
					'account':account,
					'pageNo':pageNo,
					'msgId':msgId,
					'gameType':gameType,
					'minSendTime':minSendTime,
					'maxSendTime':maxSendTime,
					'ip':ip
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					// clear previous mainDiv
					var preDlg = $("div#main>form"); 
					//preDlg.hide();
					$("div#main").empty();
					$("div#main").append(preDlg);
					$("div#main").append(data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}
	function onQueryLogger(){
		var pageNo = '1';
		var operation = $('select#operation').val();
		var operaA = $('input#operaA').val().trim() ;
		var operaB = $('input#operaB').val().trim() ;
		if($("select#pageNo").length ==1 )
			pageNo=$("select#pageNo").val();
		var pSendDate = $('input#rechargeDate').val().trim();
		var pMinSendTime = $('input#minRechargeTime').val().trim() ;
		var pMaxSendTime = $('input#maxRechargeTime').val().trim() ;
		var minRechargeTime = 0 ;
		var maxRechargeTime = 0 ;
		if(pSendDate != '' && pMinSendTime != '')
		{
			var date = newDate(pSendDate + ' ' + pMinSendTime);
			if (date)
				minRechargeTime = Date.parse(date);
			else
			{
				alert('请输入正确日期');
				return false;
			}
		}
		if(pSendDate != '' && pMaxSendTime != '')
		{
			var date = newDate(pSendDate + ' ' + pMaxSendTime);
			if (date)
				maxRechargeTime = Date.parse(date);
			else
			{
				alert('请输入正确日期');
				return false;
			}
		}

		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'queryLogger',
					'operation':operation,
					'operaA':operaA,
					'operaB':operaB,
					'pageNo':pageNo,
					'minRechargeTime':minRechargeTime,
					'maxRechargeTime':maxRechargeTime
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					// clear previous mainDiv
					var preDlg = $("div#main>form"); 
					$("div#main").empty();
					$("div#main").append(preDlg);
					$("div#main").append(data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;			
	}
	function onReportWrongAnswer(msgId)
	{
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'reportWrongAnswer',
					'msgId':msgId
				},
				url:"client",
				dataType:"text",
				success:function(data,textStatus){
					if(data == '0')
						alert('提交误报成功');
					else
						alert('提交误报失败：'+getErrorMsg(data));
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}
	function onQueryWrongAnswerRecord(){
		var pageNo = '1';
		var msgId = $('input#msgId').val().trim();
		var gameType = $('input#gameType').val().trim();
		var account = $('input#account').val().trim();
		var minSendTime = 0 ;
		var maxSendTime = 0 ;
		if($("select#pageNo").length ==1 )
			pageNo=$("select#pageNo").val();
		var pSendDate = $('input#sendDate').val().trim();
		var pMinSendTime = $('input#minSendTime').val().trim() ;
		var pMaxSendTime = $('input#maxSendTime').val().trim() ;
		var minSendTime = 0 ;
		var maxSendTime = 0 ;
		if(pSendDate != '' && pMinSendTime != '')
		{
			var date = newDate(pSendDate + ' ' + pMinSendTime);
			if (date)
				minSendTime = Date.parse(date);
			else
			{
				alert('请输入正确日期');
				return false;
			}
		}
		if(pSendDate != '' && pMaxSendTime != '')
		{
			var date = newDate(pSendDate + ' ' + pMaxSendTime);
			if (date)
				maxSendTime = Date.parse(date);
			else
			{
				alert('请输入正确日期');
				return false;
			}
		}
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'queryWrongAnswerRecord',
					'pageNo':pageNo,
					'msgId':msgId,
					'gameType':gameType,
					'account':account,
					'minSendTime':minSendTime,
					'maxSendTime':maxSendTime
				},
				url:"client",
				dataType:"text",
				success:function(data,textStatus){
					// clear previous mainDiv
					var preDlg = $("div#main>form"); 
					//preDlg.hide();
					$("div#main").empty();
					$("div#main").append(preDlg);
					$("div#main").append(data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;	
	}
	function onQueryAnswerRecord(){
		var pageNo = '1';
		var msgId = $('input#msgId').val().trim();
		var gameType = $('input#gameType').val().trim();
		var filterRight = $('select#filterRight').val();
		var minSendTime = 0 ;
		var maxSendTime = 0 ;
		if($("select#pageNo").length ==1 )
			pageNo=$("select#pageNo").val();

		var pSendDate = $('input#sendDate').val().trim();
		var pMinSendTime = $('input#minSendTime').val().trim() ;
		var pMaxSendTime = $('input#maxSendTime').val().trim() ;
		var minSendTime = 0 ;
		var maxSendTime = 0 ;
		if(pSendDate != '' && pMinSendTime != '')
		{
			//minSendTime = Date.parse(pSendDate + 'T' + pMinSendTime);
			var date = newDate(pSendDate + ' ' + pMinSendTime);
			if (date)
				minSendTime = Date.parse(date);
			else
			{
				alert('请输入正确日期');
				return false;
			}
		}
		if(pSendDate != '' && pMaxSendTime != '')
		{
			//maxSendTime = Date.parse(pSendDate + 'T' + pMaxSendTime);
			var date = newDate(pSendDate + ' ' + pMaxSendTime);
			if (date)
				maxSendTime = Date.parse(date);
			else
			{
				alert('请输入正确日期');
				return false;
			}
		}
					
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'queryAnswerRecord',
					'filterRight':filterRight,
					'pageNo':pageNo,
					'msgId':msgId,
					'gameType':gameType,
					'minSendTime':minSendTime,
					'maxSendTime':maxSendTime
				},
				url:"guest",
				dataType:"text",
				success:function(data,textStatus){
					// clear previous mainDiv
					var preDlg = $("div#main>form"); 
					//preDlg.hide();
					$("div#main").empty();
					$("div#main").append(preDlg);
					$("div#main").append(data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}	
	function onQuerySingleAccount(){
		var account = $('input#account').val().trim();
		if(account.length<32 || 
			account.indexOf('\'')>=0 ||  
			account.indexOf('"')>=0 ||	
			account.indexOf('=')>=0)
		{
			alert('请输入有效的子账号');
			return false;
		}
		return querySingleAccount(account);
	}
	
	function newUser()
 	{
 		try{
	 		var userName = $("input#userName").val().trim() ;
	 		var password = $("input#password").val().trim();
	 		var password_confirm = $("input#password_confirm").val().trim();
	 		var valid_code = $("input#validCodeAnswer").val().trim();
	 		var qq = $("input#qq").val().trim() ;
	 		var email = $("input#email").val().trim() ;
	 		if (userName == '' || password =='' || password_confirm == '' 
	 			|| valid_code == '' || qq == '' || email == '')
	 		{
	 			alert('所有输入项不能为空');
	 			return false;
	 		}
	 		if (userName.replace(/[0-9a-zA-Z_]{6,20}/g,'') != '' ||
	 			password.replace(/[0-9a-zA-Z_]{6,20}/g,'') != '')
	 		{
	 			alert('无效的用户名密码');
	 			return false;
	 		}
	 		if (password != password_confirm)
	 		{
	 			alert('二次输入的密码不匹配');
	 			return false;
	 		}
			$.ajax({
				url: 'user',
				type: "get",
				async:false,
				dataType:"text",
				data: {
			        'actionType' : 'createUser',
			        'userName' : userName,
			        'password': password,
			        'validCodeAnswer': valid_code,
			        'qq':qq,
			        'email':email
			    },
				success: function(data,textStatus) {
					if (data == '0')
					{
						alert('注册成功,请登陆');
						//relogin();
						onUserLogin(null);
					}
					else
					{
						alert(getErrMsg(data));
						show($('#validImg'));
					}
		  		}
			});
		}catch(e){
			alert(e);
		}
		return false;
	}
	function regUser()
	{
		try
		{
			$.ajax({
				type:"get",
				async:false,
				url:"user?actionType=getRegUserDlg",
				dataType:"html",
				success:function(data,textStatus){
					$("div#main").html();
					$("div#main").html(data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}	
		return false;
	}
		
	function show(o) {
  		var timenow = new Date().getTime();
  		o.src = "validatecode?d=" + timenow;
	}
	
	function userLogin(){
		var userName = $('input#userName').val().trim();
		var password = $('input#password').val().trim();
		var validCodeAnswer = $('input#validCodeAnswer').val().trim();
		try
		{
			$.ajax({
				type:"get",
				url:"user",
				async:false,
				data:{
				"actionType":"login",
				"userName":userName,
				"password":password,
				"validCodeAnswer":validCodeAnswer
				},
				dataType:"text",
				success:function(data,textStatus){
					if(data == '0')
						window.location.href="user_index.html";
					else
						alert(getErrMsg(data));
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}	
		return false;
	}
	function showDialog(data,tt){
		$('div#divDlg').html(data);
		$('div#divDlg').dialog({dialogClass:"alert",title:tt}) ;		
	}
	function guestLogin(){
		var account = $('input#account').val().trim();
		var validCodeAnswer = $('input#validCodeAnswer').val().trim();
		try
		{
			$.ajax({
				type:"get",
				url:"guest",
				async:false,
				data:{
				"actionType":"login",
				"account":account,
				"validCodeAnswer":validCodeAnswer
				},
				dataType:"text",
				success:function(data,textStatus){
					if(data.charAt(0) == '-')
						alert(getErrMsg(data));
					else
					{
						$("div#main").html("");
						$("div#main").show();
						showDialog(data);
					}
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}	
		return false;
	}	
	/*
	function onUserLogin(){
		try
		{
			$.ajax({
				type:"get",
				url:"user",
				async:false,
				data:{
				"actionType":"getLoginDlg"
				},
				dataType:"html",
				success:function(data,textStatus){
					showDialog(data,"开发者登陆");
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}	
		return false;
	}
	function guestLogin(){
		var account = $('input#account').val().trim();
		var validCodeAnswer = $('input#validCodeAnswer').val().trim();
		try
		{
			$.ajax({
				type:"get",
				url:"guest",
				async:false,
				data:{
				"actionType":"login",
				"account":account,
				"validCodeAnswer":validCodeAnswer
				},
				dataType:"text",
				success:function(data,textStatus){
					if(data.charAt(0) == '-')
						alert(getErrMsg(data));
					else
					{

						// update main navigater
						$('a[name="mainNavBar"]').each(function(i,ele){jQuery.attr(ele,'class','');});					
						var element = $('a[name="mainNavBar"]').get(2);
						jQuery.attr(element,'class','active');
					
						var json = jQuery.parseJSON(data);
						// update sider bar				
						var sideNav = $("ul.sideNav");
							sideNav.empty();	
							$.each(json,function(i,item){
							var siderBar = '<li><a href="'+item.url+ '" id="' + item.id +
										'" name="sideNavBar" onclick="onClickSideBar(this);return false;">'+
										item.title+'</a></li>';
							sideNav.append(siderBar);
						});
					
						// clear previous mainDiv
						$('div[name="contentDiv"]').each(function(i,ele){
							ele.style.display='none';
							//ele.hide("slide");
						});
						$("div#main").html("");
						$("div#main").show();
						return false ;
					}
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}	
		return false;
	}
	*/
	function onGuestLogin(element){
	

	//	var currentText = $("#datepicker").datepicker( "option", "currentText" );
		//alert(currentText);
		try
		{
			$.ajax({
				type:"get",
				url:"guest",
				async:false,
				data:{
				"actionType":"getLoginDlg"
				},
				dataType:"html",
				success:function(data,textStatus){
					// update main navigater
					$('a[name="mainNavBar"]').each(function(i,ele){jQuery.attr(ele,'class','');});					
					jQuery.attr(element,'class','active');				
					$("div#main").html();
					$("div#main").html(data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}	
		return false;
	}
	function onUserLogin(element){
		try
		{
			$.ajax({
				type:"get",
				url:"user",
				async:false,
				data:{
				"actionType":"getLoginDlg"
				},
				dataType:"html",
				success:function(data,textStatus){
					// update main navigater
					$('a[name="mainNavBar"]').each(function(i,ele){jQuery.attr(ele,'class','');});					
					if(element)
					jQuery.attr(element,'class','active');
					$("div#main").html();
					$("div#main").html(data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}	
		return false;
	}
	function rechargeAccount(){
		var account = $("input#account").val().trim();
		var rechargeCard = $("input#rechargeCard").val().trim();
		if (account == '' || rechargeCard == '')
		{
			alert('输入项不能为空');
			return false;
		}
		
		try
		{
			$.ajax({
				type:"get",
				async:false,
				data:{
					'actionType':'rechargeAccount',
					'account':account,
					'rechargeCard':rechargeCard
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					if(data.charAt(0) >= '0' && data.charAt(0) <= '9')
					{
						alert('充值成功,点数为:'+data);
					}
					else
						alert('充值失败:'+getErrMsg(data));
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}	
		return false;
	}
	function mergeAccount(){
		var accountA = $("input#accountA").val().trim();
		var accountB = $("input#accountB").val().trim();
		if (accountA == '' || accountB == '')
		{
			alert('输入项不能为空');
			return false;
		}
		
		try
		{
			$.ajax({
				type:"get",
				async:false,
				data:{
					'actionType':'mergeAccount',
					'accountA':accountA,
					'accountB':accountB
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					if(data.charAt(0) >= '0' && data.charAt(0) <= '9')
					{
						var strs = data.split(',');
						alert('充值成功,充值后的点数为:'+strs[2]);
					}
					else
						alert('充值失败:'+getErrMsg(data));
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}	
		return false;
	}	
	function rechargeUser(){
		var userName = $("input#userName").val().trim();
		var rechargeCard = $("input#rechargeCard").val().trim();
		if (userName == '' || rechargeCard == '')
		{
			alert('输入项不能为空');
			return false;
		}
		
		try
		{
			$.ajax({
				type:"get",
				async:false,
				data:{
					'actionType':'rechargeUser',
					'userName':userName,
					'rechargeCard':rechargeCard
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					if(data.charAt(0) >= '0' && data.charAt(0) <= '9')
					{
						alert('充值成功,点数为:'+data);
					}
					else
						alert('充值失败:'+getErrMsg(data));
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}	
		return false;
	}
	function recycleRechargeCard(rechargeCard){
	
		if(!confirm("确定要删除充值卡:"+rechargeCard))
			return false ;
		try
		{
			$.ajax({
				type:"get",
				async:false,
				data:{
					'actionType':'recycleRechargeCard',
					'rechargeCard':rechargeCard
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					if(data == '0')
					{
						var eId = rechargeCard.replace('|','\\|');
						$("#"+eId).empty();
					//	alert('删除成功:'+rechargeCard);
					}
					else
						alert('删除失败:'+getErrMsg(data));
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}
	function querySingleRechargeCard(rechargeCard){
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'querySingleRechargeCard',
					'rechargeCard':rechargeCard
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					alert(getErrMsg(data));
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}
	
	function onQueryRechargeCard(){
		var rechargeCard = $("input#rechargeCard").val().trim() ;
		var min_validDate_year = $("select#min_validDate_year").val();
		var min_validDate_month = $("select#min_validDate_month").val();
		var min_validDate_day = $("select#min_validDate_day").val();
		var min_validDate = min_validDate_year + '-' + min_validDate_month + '-' + min_validDate_day;
		
		var max_validDate_year = $("select#max_validDate_year").val();
		var max_validDate_month = $("select#max_validDate_month").val();
		var max_validDate_day = $("select#max_validDate_day").val();
		var max_validDate = max_validDate_year + '-' + max_validDate_month + '-' + max_validDate_day;		
	
		var min_point = $("input#min_point").val().trim() ;
		var max_point = $("input#max_point").val().trim() ;
		
		var pageNo = '1';
		if($("select#pageNo").length == 1)
			pageNo=$("select#pageNo").val();
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'queryRechargeCard',
					'rechargeCard':rechargeCard,
					'minValidDate':min_validDate,
					'maxValidDate':max_validDate,
					'minPoint':min_point,
					'maxPoint':max_point,
					'pageNo':pageNo
				},
				url:"user",
				dataType:"html",
				success:function(data,textStatus){
					// clear previous mainDiv
					var preDlg = $("div#main>form"); 
					//preDlg.hide();
					$("div#main").empty();
					$("div#main").append(preDlg);
					$("div#main").append(data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}
	function onCreateRechargeCard(){
		try{
			var userName = $("input#userName").val().trim();
			var password = $("input#password").val().trim();
			var point = $("input#point").val();
			var batchSize = $("input#batchSize").val();
			var year = $("select#validDate_year").val();
			var month = $("select#validDate_month").val();
			var day = $("select#validDate_day").val();
			var validDate = year+'-'+month+'-'+day;
			
			if (userName=='' || password == '' || point == '' ||
					batchSize == '' || year == '' || month == '' || day == '')
			{
				alert('输入项不能为空') ;
				return false ;
			}
			
			// send ajax request
			$.ajax({
				type: "get",
				async:false,
				data:{
					'actionType':'createRechargeCard',
					'userName':userName,
					'password':password,
					'point':point,
					'batchSize':batchSize,
					'validDate':validDate
				},
				dataType:"text",
				cache:false,
				url: 'user',
				beforeSend: function(XMLHttpRequest){
				//ShowLoading();
				},
				success: function(data, textStatus){
					if (data.length <32)
					{
						alert('创建充值卡失败：'+getErrMsg(data));
					}
					else
					{
						var accountList = data.split(',');
						var accounts = '共创建'+accountList.length+'张充值卡：\n';
						for(var i = 0 ; i < accountList.length ; i++)
							accounts += accountList[i] + '\t\t\n';
						//alert(accounts);
						showDialog(accounts,"充值卡");
					}
					return false ;
					
				},
				complete: function(XMLHttpRequest, textStatus){
				//HideLoading();
				},
				error: function (XMLHttpRequest, textStatus, errorThrown){ 
	                alert('创建充值卡失败：'+XMLHttpRequest.responseText+textStatus);
	                return false ;
	            }
			});	
		}
		catch(e){
			alert(e);
		}
		return false ;
	}	
	function freezeAccount(account){
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'freezeAccount',
					'account':account
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					if('0' == data)
						showDialog('冻结子账号'+account+'成功');
					else
						showDialog('冻结子账号'+account+'失败:'+data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;	
	}
	function unfreezeAccount(account){
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'unfreezeAccount',
					'account':account
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					if('0' == data)
						showDialog('解冻子账号'+account+'成功');
					else
						showDialog('解冻子账号'+account+'失败:'+data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;	
	}
	function recycleAccount(account){
	
		if(!confirm("确定要删除子账号:"+account+'\n(该账号将在30秒后彻底删除)?'))
			return false ;
		try
		{
			$.ajax({
				type:"get",
				async:false,
				data:{
					'actionType':'recycleAccount',
					'account':account
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					if(data == '0')
					{
						var eId = account.replace('|','\\|');
						$("#"+eId).empty();
					}
					else
						alert('删除失败:'+getErrMsg(data));
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}
	function querySingleAccount(account){
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'querySingleAccount',
					'account':account
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					showDialog(data,'子帐号明细');
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}
	function onUpdateAccount(account){
		try
		{
			$.ajax({
				type:"get",
				async:false,
				data:{
					'actionType':'getUpdateSingleAccountDlg',
					'account':account
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					showDialog(data,'更新子账号');
				}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;	
	}
	function updateAccount(){
		try
		{
			var account = $('input#account1').val();
			var point = $('input#point').val().trim();
			var validDate = $('input#validDate').val().trim();
			$.ajax({
				type: "get",
				async:false,
				data:{
					'actionType':'updateSingleAccount',
					'account1':account,
					'point':point,
					'validDate':validDate
				},
				dataType:"text",
				cache:false,
				url: 'user',
				success: function(data, textStatus){
					
					if (data == '0')
					{
						alert('更新子账号成功:'+account);
					}
					else
					{
						alert('更新子账号失败:'+getErrMsg(data));
					}
					return false ;
					
				}
			});	
		}catch(e){
			return false ;
		}
		return false ;		
	}
	function onQueryAccount(){
		var account = $("input#account").val().trim() ;
		var min_validDate_year = $("select#min_validDate_year").val();
		var min_validDate_month = $("select#min_validDate_month").val();
		var min_validDate_day = $("select#min_validDate_day").val();
		var min_validDate = min_validDate_year + '-' + min_validDate_month + '-' + min_validDate_day;
		if ((min_validDate_year != '' || min_validDate_month != '' ||  min_validDate_day != '') && 
			min_validDate.length != 10)
		{
			alert('请输入完整的日期');
			return ;
		}  
		var max_validDate_year = $("select#max_validDate_year").val();
		var max_validDate_month = $("select#max_validDate_month").val();
		var max_validDate_day = $("select#max_validDate_day").val();
		var max_validDate = max_validDate_year + '-' + max_validDate_month + '-' + max_validDate_day;		
		if ((max_validDate_year != '' || max_validDate_month != '' ||  max_validDate_day != '') && 
			max_validDate.length != 10)
		{
			alert('请输入完整的日期');
			return ;
		}  
		
		var min_left_point = $("input#min_left_point").val().trim() ;
		var max_left_point = $("input#max_left_point").val().trim() ;
		
		var pageNo = '1';
		if($("select#pageNo").length == 1)
			pageNo=$("select#pageNo").val();
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'queryAccount',
					'account':account,
					'minValidDate':min_validDate,
					'maxValidDate':max_validDate,
					'minLeftPoint':min_left_point,
					'maxLeftPoint':max_left_point,
					'pageNo':pageNo
				},
				url:"user",
				dataType:"html",
				success:function(data,textStatus){
					// clear previous mainDiv
					var preDlg = $("div#main>form"); 
					//preDlg.hide();
					$("div#main").empty();
					$("div#main").append(preDlg);
					$("div#main").append(data);
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}
	function onCreateAccount(){
		try{
			var userName = $("input#userName").val().trim();
			var password = $("input#password").val().trim();
			var point = $("input#point").val();
			var batchSize = $("input#batchSize").val();
			var year = $("select#validDate_year").val();
			var month = $("select#validDate_month").val();
			var day = $("select#validDate_day").val();
			var validDays = $('input#validDays').val();
			if (userName=='' || password == '' || point == '' ||
					batchSize == '' || ((year == '' || month == '' || day == '') &&(validDays=='')))
			{
				alert('输入项不能为空') ;
				return false ;
			}
			var validDate = year+'-'+month+'-'+day;
			if (validDays)
				validDate = validDays ;
				
			
			// send ajax request
			$.ajax({
				type: "get",
				async:false,
				data:{
					'actionType':'createAccount',
					'userName':userName,
					'password':password,
					'point':point,
					'batchSize':batchSize,
					'validDate':validDate
				},
				dataType:"text",
				cache:false,
				url: 'user',
				beforeSend: function(XMLHttpRequest){
				//ShowLoading();
				},
				success: function(data, textStatus){
					if (data.length <32)
					{
						alert('创建账号失败：'+getErrMsg(data));
					}
					else
					{
						var accountList = data.split(',');
						var accounts = '共创建'+accountList.length+'个账号：\n';
						for(var i = 0 ; i < accountList.length ; i++)
							accounts += accountList[i] + '\t\t\n';
						//alert(accounts);
						//accounts = '<textarea height=100% width=100% >'+accounts+'</textarea>';
						showDialog(accounts,"子账号");
					}
					return false ;
					
				},
				complete: function(XMLHttpRequest, textStatus){
				//HideLoading();
				},
				error: function (XMLHttpRequest, textStatus, errorThrown){ 
	                alert('创建账号失败：'+XMLHttpRequest.responseText);
	                return false ;
	            }
			});	
		}
		catch(e){
			alert(e);
		}
		return false ;
	}

	function onClickSideBar(element){
		try
		{
			// update side bar status
			$('a[name="sideNavBar"]').each(function(i,ele){jQuery.attr(ele,'class','');});					
			jQuery.attr(element,'class','active');
						
			// send ajax request
			$.ajax({
				type: "get",
			//	async:false,
				cache:false,
				url: element.href,
				dataType:"text",
				beforeSend: function(XMLHttpRequest){
				//ShowLoading();
				},
				success: function(data, textStatus){
					// clear main div
					//if(element.type != 'submit')
					$("div#main").empty();
					// clear previous mainDiv
					$("div#main").append(data);
					
					/* init date time picker
					$("input.datepicker").each(function(i,ele){
						ele.datepicker({disabled:true});
					}) ;
					*/
					
					return false ;
				},
				complete: function(XMLHttpRequest, textStatus){
				//HideLoading();
				},
				error: function (XMLHttpRequest, textStatus, errorThrown){ 
					alert(textStatus+':'+XMLHttpRequest.reponseText);
	                return false ;
	            }
			});	
		}
		catch(e){
			alert(e);
		}
		
		return false ;
	}
	function onShowImage(fileName){
		var data = '<img src='+fileName +' ></img>';
		$('div#divDlg').html(data);
		$('div#divDlg').dialog({dialogClass:"alert"}) ;	
	}
	function onClickMainNavBar(element){
		try
		{
			$.ajax({
				type: "get",
				async:false,
				dataType: "json",
				cache:false,
				url: element.href,
				beforeSend: function(XMLHttpRequest){
				//ShowLoading();
				},
				success: function(data, textStatus){
					// update main navigater
					$('a[name="mainNavBar"]').each(function(i,ele){jQuery.attr(ele,'class','');});					
					jQuery.attr(element,'class','active');
					
					// update sider bar				
					var sideNav = $("ul.sideNav");
					sideNav.empty();	
					$.each(data,function(i,item){
						var siderBar = '<li><a href="'+item.url+ '" id="' + item.id +
									'" name="sideNavBar" onclick="onClickSideBar(this);return false;">'+
									item.title+'</a></li>';
						sideNav.append(siderBar);
					});
					
					// clear previous mainDiv
					$('div[name="contentDiv"]').each(function(i,ele){
						ele.style.display='none';
						//ele.hide("slide");
					});
					$("div#main").html("");
					$("div#main").show();
					return false ;
				},
				complete: function(XMLHttpRequest, textStatus){
					return false ;
				},
				error: function (XMLHttpRequest, textStatus, errorThrown){ 
					alert(XMLHttpRequest.responseText+':'+textStatus);
					return false ;
	            }
			});	
		}
		catch(e){
			alert(e);
		}
		// 防止触发页面跳转
		return false ;
	}
	function onReturnPoint2Point()
	{
		var returnPoint = $('input#returnPoint').val().trim() ;
		try
		{
			$.ajax({
				type:"get",
				async:false,
				cache:false,
				data:{
					'actionType':'returnPoint2Point',
					'returnPoint':returnPoint
				},
				url:"user",
				dataType:"text",
				success:function(data,textStatus){
					showDialog(data,'返点兑换');
				},
				error:function(){}
			});
		}catch(e){
			alert(e);
			return false ;
		}
		return false ;
	}
	function getErrorMsg(errCode)
	{
		if(errCode == "-19")
			return "其他异常";
		if(errCode == "-18")
			return "客户端已登陆";
		if(errCode == "-17")
			return "调用次数过多|频率过高";
		if(errCode == "-16")
			return "开发者账号点数不足";
		if(errCode == "-15")
			return "请先登录";
		if(errCode == "-14")
			return "过期的账号或者充值卡";
		if(errCode == "-13")
			return "验证码错误";
		if(errCode == "-12")
			return "用户或子账号已存在";
		if(errCode == "-11")
			return "充值卡号已使用";
		if(errCode == "-10")
			return "无效的账号或者充值卡号";
		if(errCode == "-9")
			return "子账号剩余点数不足";
		if(errCode == "-8")
			return "发送文件失败";
		if(errCode == "-7")
			return "参数缺失";
		if(errCode == "-6")
			return "无效的用户名或密码";
		if(errCode == "-5")
			return "服务器繁忙";
		if(errCode == "-4")
			return "请使用同一开发者生成的充值卡或子账号";
		if(errCode == "-3")
			return "参数值异常,如无效的项目类型、废弃账号等";
		if(errCode == "-2")
			return "答案未准备好";
		if(errCode == "-1")
			return "网络异常";
		if(errCode == "0")
			return "成功";
		return errCode;
	}	
//}());